/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.jm.financeiro.entity;

import br.jm.financeiro.filter.ConfiguraCampoAnnotation;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

/**
 *
 * @author joao
 */
@Entity
@Table(name = "cliente_endereco", catalog = "salao", schema = "public")
public class ClienteEndereco implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "cliente_endereco_id_endereco_seq")
    @SequenceGenerator(name = "cliente_endereco_id_endereco_seq", sequenceName = "cliente_endereco_id_endereco_seq", initialValue = 1, allocationSize = 1)
    @Column(name = "id_endereco")
    @JoinColumn(name = "id_endereco",
    referencedColumnName = "id_endereco",
    nullable = false,
    insertable = true,
    updatable = false)
    private Integer idEndereco;
    @Basic(optional = false)
    @Column(name = "tip_endereco", nullable = false, length = 1)
    private String tipEndereco;
    @Basic(optional = false)
    @Column(name = "dsc_endereco", nullable = false, length = 40)
    private String dscEndereco;
    @Column(name = "dsc_complemento", length = 50)
    private String dscComplemento;
    @Basic(optional = false)
    @Column(name = "num_endereco", nullable = false, length = 10)
    private String numEndereco;
    @Transient
    private String dscTipo;
    @JoinColumn(name = "id_cliente", referencedColumnName = "id_cliente", nullable = false)
    @ManyToOne(optional = false)
    @ConfiguraCampoAnnotation(tipo = "int", pesquisa = "idCliente", campo = "id_cliente", nomeTabela = "cliente_endereco", nomeTabelJoin = "cliente_endereco")
    private Cliente idCliente;
    @JoinColumn(name = "cod_logradouro", referencedColumnName = "cod_logradouro", nullable = false)
    @ManyToOne(optional = false)
    private CepEndereco codLogradouro;

    public ClienteEndereco() {
    }

    public ClienteEndereco(Integer idEndereco) {
        this.idEndereco = idEndereco;
    }

    public ClienteEndereco(Integer idEndereco, String tipEndereco, String dscEndereco, String numEndereco) {
        this.idEndereco = idEndereco;
        this.tipEndereco = tipEndereco;
        this.dscEndereco = dscEndereco;
        this.numEndereco = numEndereco;
    }

    public Integer getIdEndereco() {
        return idEndereco;
    }

    public void setIdEndereco(Integer idEndereco) {
        this.idEndereco = idEndereco;
    }

    public String getTipEndereco() {
        return tipEndereco;
    }

    public void setTipEndereco(String tipEndereco) {
        this.tipEndereco = tipEndereco;
    }

    public String getDscEndereco() {
        return dscEndereco;
    }

    public void setDscEndereco(String dscEndereco) {
        this.dscEndereco = dscEndereco;
    }

    public String getDscComplemento() {
        return dscComplemento;
    }

    public void setDscComplemento(String dscComplemento) {
        this.dscComplemento = dscComplemento;
    }

    public String getNumEndereco() {
        return numEndereco;
    }

    public void setNumEndereco(String numEndereco) {
        this.numEndereco = numEndereco;
    }

    public Cliente getIdCliente() {
        return idCliente;
    }

    public void setIdCliente(Cliente idCliente) {
        this.idCliente = idCliente;
    }

    public CepEndereco getCodLogradouro() {
        return codLogradouro;
    }

    public void setCodLogradouro(CepEndereco codLogradouro) {
        this.codLogradouro = codLogradouro;
    }

    public String getDscTipo() {
        if (this.tipEndereco != null) {
            if (this.tipEndereco.equals("1")) {
                this.dscTipo = "Comercial";
            } else if (this.tipEndereco.equals("2")) {
                this.dscTipo = "Residencial";
            } else if (this.tipEndereco.equals("3")) {
                this.dscTipo = "Filial";
            } else if (this.tipEndereco.equals("4")) {
                this.dscTipo = "Cobrança";
            } else {
                this.dscTipo = "";
            }
        }
        return dscTipo;
    }

    public void setDscTipo(String dscTipo) {
        this.dscTipo = dscTipo;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idEndereco != null ? idEndereco.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ClienteEndereco)) {
            return false;
        }
        ClienteEndereco other = (ClienteEndereco) object;
        if ((this.idEndereco == null && other.idEndereco != null) || (this.idEndereco != null && !this.idEndereco.equals(other.idEndereco))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.jm.financeiro.entity.ClienteEndereco[ idEndereco=" + idEndereco + " ]";
    }
    /*
     public List<ClienteEnderecoTelefone> getClienteEnderecoTelefoneList() {
     return clienteEnderecoTelefoneList;
     }

     public void setClienteEnderecoTelefoneList(List<ClienteEnderecoTelefone> clienteEnderecoTelefoneList) {
     this.clienteEnderecoTelefoneList = clienteEnderecoTelefoneList;
     }
     * 
     */
}
